import numpy as np

if __name__ == "__main__":
    print("numpy func test!")

    # np.split用法https://blog.csdn.net/helloword111222/article/details/120584744
    arr1 = np.array([1,2,3,4])
    print(arr1)
    print(np.split(arr1,2))
    arr_test = np.split(arr1,2)
    print(arr_test[1])

    arr2 = np.array([[1,2,3],[4,5,6]])
    print(arr2.shape)

    # np.reshape用法 https://www.python100.com/html/104649.html
    print(arr2.reshape(3,2))

    arr3 = np.array([[1,2,3],[4,5,6],[7,8,9]]).astype(np.float32)
    print(arr3)
    print(np.max(arr3,axis=0)) #按行取最大数，组成新的数组
    print(np.max(arr3,axis=1)) #按列取最大数，组成新的数组

    # np.newaxis用法 https://blog.csdn.net/TheMountainGhost/article/details/124148047
    print(arr1[np.newaxis,]) # 放在前面，会给行上增加维度
    print(arr1[np.newaxis,].shape) 

    # np.transpose # https://blog.csdn.net/l8947943/article/details/105704696/
    print('------------')
    x = np.arange(12).reshape((2,3,2))
    print(x)
    print('------------')
    print(x.transpose(1,2,0)) 

    y = np.array([[0,1,2],[0,1,2],[0,1,2]])
    y =y[np.newaxis,]
    print('------------')
    print(y.transpose(0,2,1))

    #np.argmax() 函数返回数组中最大值的索引。
    #np.max() 则是返回最大值

    #np.where https://blog.csdn.net/mzy20010420/article/details/126994743
    a = np.array([2, 4, 6, 8, 10])
    #一维矩阵
    result_1 = np.where(a > 5)
    print(result_1)
    #二维
    # print('------------')
    b = np.random.randn(3, 3)
    print(f'b = {b}')
    c = np.where(b > 0)
    print(f'c = {c}') #返回的是下标，第一个元组的x，第二个元组是y。

    tensor = np.array([[[1, 2, 3],
                    [4, 5, 6]],
                   [[7, 8, 9],
                    [10, 11, 12]]])

    # 取出 [2, 2] 维度的所有值
    sub_tensor = tensor[1,1]  # 获取最后一个维度（索引为 -1）的所有值

    # 输出结果
    print("SubTensor contents (2x2):")
    print(sub_tensor)

    print('-------------------')
    aa = np.array([[1,2],[3,4]])
    bb = np.array([[5,6],[7,8]])
    print(np.dot(aa,bb))
